var max_y : int = 60;
var min_y : int = -60;
var xyaxis : int; // 0 y, 1 x, 2 xy, 3 xy dragon)
var sensitivity : int = 10;

private var zerorot : Quaternion;
private var newrot : Vector3;
private var mousedelta : Vector3;
var rotrestimer : float;

function Start() 
{

}

function Update() 
{
	mousedelta = Vector3(Input.GetAxis("Mouse X"),-Input.GetAxis("Mouse Y"),0);
	mousedelta *= sensitivity;
	
	newrot.y = transform.eulerAngles.y;
	newrot.z = transform.eulerAngles.z;
	
	if(xyaxis==0)
	{
		newrot.x += mousedelta.y;
		newrot.x = Mathf.Clamp (newrot.x, min_y, max_y);
		transform.localEulerAngles = newrot;
	}
	else if(xyaxis==1)
	{		
		transform.Rotate(0,mousedelta.x,0,Space.World);
	}		
	else if(xyaxis==2)
	{
		newrot.x += mousedelta.y;
		newrot.x = Mathf.Clamp (newrot.x, min_y, max_y);
		transform.localEulerAngles = newrot;
		transform.Rotate(0,mousedelta.x,0,Space.World);
	}
	else if(xyaxis==3)
	{
		transform.Rotate(mousedelta.y,mousedelta.x,0);
		if(!mousedelta.y)
		{
			if(rotrestimer<2) rotrestimer += Time.deltaTime;
			zerorot =  Quaternion.Euler(0, transform.eulerAngles.y, 0);
			transform.localRotation = Quaternion.RotateTowards(transform.rotation,zerorot,0.5*rotrestimer);
		}
		else {rotrestimer = 0;}
	}
}